package com.qiaofang.common.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.UnsupportedEncodingException;

public class PasswordUtil {

    /**
     * md5 key
     */
    private static String KEY = "qfb_jr_";

    /**
     *
     */
    private static String INITIAL_PASSWORD = "qfb_jr_";


    public static String resetPassword() {
        return md5Hex("12345678");
    }

    public static String md5Hex(String password) {
        String tempPwd = KEY + password;
        return DigestUtils.md5Hex(getContentBytes(tempPwd, "utf-8"));
    }

    private static byte[] getContentBytes(String content, String charset) {
        if (charset == null || "".equals(charset)) {
            return content.getBytes();
        }
        try {
            return content.getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset);
        }
    }

    public static void main(String[] args) {
        System.out.println(PasswordUtil.md5Hex("123"));
    }

}
